{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
      <div class="layui-inline">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
          <select class="layui-input" name='status' id='status'>
            <option value="">全部</option>
            <option value="1">通过</option>
            <option value="0">待审核</option>
            <option value="-1">已拒绝</option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">地址</label>
          <div class="layui-input-inline">
              <input type="text" name="address" autocomplete="off" class="layui-input" id='address'>
          </div>
      </div>
     
      <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn" data-type="reload">搜索</button>
          <!-- <button class="layui-btn" onclick="excel()">导出表</button> -->
        </div>
      </div>
  <table id="table" lay-filter="test"></table> 
    <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
    <!-- <a class="layui-btn layui-btn-xs" lay-event="bf">补发</a> -->
  </script>
  <script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="copy">复制钱包地址</a>
  </script>
  <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <!-- <button class="layui-btn layui-btn-sm" lay-event="add">一键审核</button> -->
  </div>
</script>
</div>
{/block}
{block name="script"}
<script src="/static/dist/clipboard.min.js"></script>
<script>

layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    // ,defaultToolbar: ['filter']
    // ,toolbar: '#toolbarDemo'

    ,height: 'full-200'
    ,url: '/admin/record/outList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      // {type: 'checkbox', fixed: 'left'}
      {field:'uid', title: '用户ID', width: 100}
      ,{field:'address', title: '地址', width: 300}
      ,{field:'total_amount', title: '提币数量', width: 100}
      ,{field:'fee', title: '手续费', width: 100}
      ,{field:'amount', title: '到账数量', width: 100,templet: function(d){
          return '<span style="color:red">'+d.amount+'</span>'
      }}
       ,{field:'status', title: '是否通过', width: 100,templet: function(d){
        if (d.status == 1) {
          return '<span style="color:red">已通过</span>'
        }
        if (d.status == 0) {
          return '<span style="color:green">待审核</span>'
        }
        if (d.status == -1) {
          return '<span style="color:blue">已拒绝</span>'
        }
      }}
      ,{title: '操作', toolbar: '#barDemo', width: 200}
      
    ]]
  });
    //监听表格复选框选择
  table.on('checkbox(test)', function(obj){
   //console.log(obj)
  });
  //监听事件
// table.on('toolbar(test)', function(obj){
//   var checkStatus = table.checkStatus(obj.config.id);
//   switch(obj.event){
//     case 'add':
//         var da = checkStatus.data;
//         if (da.length == 0) {
//           layer.msg('未选择记录');
//           return;
//         }
//         layer.prompt({
//             formType: 2,    // 弹出文本层类型
//             title: '请输入审核备注',    // 标题
//             value:'',    // 可以设置文本默认值
//             area: ['300px', '100px'],     // 设置弹出层大小
//             btn: ['拒绝', '通过','取消'],    // 自定义设置多个按钮
//             btn2: function(index, elem){
//                     // 得到value
//             var value = layui.jquery('#layui-layer'+index + " .layui-layer-input").val();
//             var index = layer.msg('正在拼命处理...' , {
//           icon: 16 ,
//           shade: 0.6 ,
//           time: 0 ,
//         });
//             $.ajax({
//               url:"{:url('admin/out/pass2')}",
//               type:"POST",
//               data:{data:JSON.stringify(da),value:value},
//               success:function(ret){
//                   if (ret.code == 0) {
//                     layer.msg('操作成功');
//                     $(".layui-laypage-btn")[0].click();
//                   }
//                   if (ret.code == 1) {
//                     layer.msg(ret.msg);
//                     $(".layui-laypage-btn")[0].click();
//                   }
//               }
//             });
//                layer.close(index);
//             },
//             btnAlign: 'c',    // 设置按钮位置
//         }, function(value, index, elem){
//           var index = layer.msg('正在拼命处理...' , {
//           icon: 16 ,
//           shade: 0.6 ,
//           time: 0 ,
//         });
//           $.ajax({
//             url:"{:url('admin/out/refuse2')}",
//             type:"POST",
//             data:{data:JSON.stringify(da),value:value},
//             success:function(ret){
//                 if (ret.code == 0) {
//                   layer.msg('操作成功');
//                   $(".layui-laypage-btn")[0].click();
//                 }
//                 if (ret.code == 1) {
//                     layer.msg(ret.msg);
//                 }
//             }
//           });
//             layer.close(index);
//         }); 
//     break;
//   };
// });
  table.on('tool(test)', function(obj){
    var data = obj.data;
     if(obj.event === 'edit'){
      layer.prompt({
            formType: 2,    // 弹出文本层类型
            title: '请输入审核备注',    // 标题
            value:'',    // 可以设置文本默认值
            area: ['300px', '100px'],     // 设置弹出层大小
            btn: ['拒绝', '通过','取消'],    // 自定义设置多个按钮
            btn2: function(index, elem){
            // 得到value
            var value = layui.jquery('#layui-layer'+index + " .layui-layer-input").val();
            var index = layer.msg('正在拼命处理...' , {
              icon: 16 ,
              shade: 0.6 ,
              time: 0 ,
            });
            $.ajax({
              url:"{:url('admin/record/pass')}",
              type:"POST",
              data:{id:data.id,value:value},
              success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                    $(".layui-laypage-btn")[0].click();
                }
            }
        });
                　 layer.close(index);
            },
            btnAlign: 'c',    // 设置按钮位置
        }, function(value, index, elem){
            var index = layer.msg('正在拼命处理...' , {
            icon: 16 ,
            shade: 0.6 ,
            time: 0 ,
          });
            $.ajax({
            url:"{:url('admin/record/refuse')}",
            type:"POST",
            data:{id:data.id,value:value},
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
            layer.close(index);
        }); 
     }
      if(obj.event === 'bf'){
        layer.confirm('慎重！请先通过hash值确认提币自动下发失败后再补发', {
          btn: ['确定'] //按钮
        }, function(){
           var index = layer.msg('正在拼命处理...' , {
          icon: 16 ,
          shade: 0.6 ,
          time: 0 ,
        });
          $.ajax({
            url:"{:url('admin/out/bf')}",
            type:"POST",
            data:{id:data.id},
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
        });
      }
      if(obj.event === 'copy'){
              $(".font-primary").attr("data-clipboard-text",data.address);
                var clipboard = new ClipboardJS('.font-primary');
                clipboard.on('success', function(e) {
                    layer.msg('复制成功');
                    clipboard.destroy();  //解决多次弹窗
                    e.clearSelection();
                });

      }
  });
    // 搜索
  var $ = layui.$, active = {
        reload: function(){
            table.reload('reload', {
                where: {
                    uid: $('#uid').val(),
                    status: $('#status').val(),
                    address: $('#address').val(),
                    coin_name: $('#coin_name').val(),
                    wallet_name: $('#wallet_name').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
            });
        }
    };
    $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
      //日期
  laydate.render({
    elem: '#start_time'
  });
  laydate.render({
    elem: '#end_time'
  });
});
function excel(){
  // var index = layer.msg('正在拼命处理...' , {
  //       icon: 16 ,
  //       shade: 0.6 ,
  //       time: 0 ,
  //     });
  var post_data = {
                    uid: $('#uid').val(),
                    status: $('#status').val(),
                    username: $('#username').val(),
                    coin_name: $('#coin_name').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
  $.ajax({
    url:"{:url('admin/out/excel')}",
    type:"POST",
    data:post_data,
    success:function(ret){
      //alert(ret);
      location.href='/'+ret;
    }
  }); 
}
</script>
{/block}
